package breeze.tool.life.broadcasts;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
import android.content.Context;
import android.content.Intent;
import java.util.Calendar;
import android.widget.RemoteViews;
import breeze.tool.life.R;
import android.content.ComponentName;
import android.icu.text.SimpleDateFormat;

public class GaokaoTimeWidget extends AppWidgetProvider{
    
    /*
	*@author BREEZE
	*@date 2021-11-21 07:53:01
    */
    public static final String TAG = "GaokaoTimeWidget";

	@Override
	public void onEnabled(Context context) {
		updateWidget(context);
		super.onEnabled(context);
	}

	@Override
	public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
		updateWidget(context);
		super.onUpdate(context, appWidgetManager, appWidgetIds);
	}

	@Override
	public void onReceive(Context context, Intent intent) {
		super.onReceive(context, intent);
	}
	
	private void updateWidget(Context context){
		AppWidgetManager awm = AppWidgetManager.getInstance(context);
		RemoteViews rmv = new RemoteViews(context.getPackageName(),R.layout.layout_widget_gaokao);
		rmv.setTextViewText(R.id.layoutwidgetgaokaoTextView1,String.valueOf(getTime()));
		ComponentName cn = new ComponentName(context,GaokaoTimeWidget.class);
		awm.updateAppWidget(cn,rmv);
	}
	
	public static int getTime(){
		Calendar mGaokaoCalendar = Calendar.getInstance();
		//设置高考时间
		mGaokaoCalendar.set(Calendar.YEAR,2022);
		mGaokaoCalendar.set(Calendar.MONTH,5);
		mGaokaoCalendar.set(Calendar.DAY_OF_MONTH,6);
		mGaokaoCalendar.set(Calendar.MINUTE,0);
		mGaokaoCalendar.set(Calendar.HOUR_OF_DAY,0);
		mGaokaoCalendar.set(Calendar.SECOND,0);
		mGaokaoCalendar.set(Calendar.MILLISECOND,0);
		long time = mGaokaoCalendar.getTimeInMillis();
		return Integer.valueOf(new SimpleDateFormat("D").format(time-System.currentTimeMillis()));
	}
    
}
